import './index.scss';
import tpl from './index.tpl';
//import two files

//exports
export default () => {
  return {
    name: 'header', //module flag name
    showRemove: false,
    tpl (opt) {
      let oHeader = document.createElement('div');
      oHeader.className = 'header';
      //tpl is a function
      oHeader.innerHTML = tpl().replace(/{{(.*?)}}/g, (node ,key)=> {
        return {
          title: opt.title,
          is_show: opt.is_show ? 'show': '',
          content: opt.content
        }[key];
      });
      return oHeader;
    },
    onShowRemoveBtn() {
      if(this.showRemove === false){
        this.showRemove = true;
      }else{
        this.showRemove = false;
      }

      const oRemoveCell = Array.from(document.getElementsByClassName('remove-cell')),
            oEditBtn = document.getElementsByClassName('J_editRemove')[0];

      if(this.showRemove){
        oRemoveCell.forEach((elem)=> {
          oEditBtn.innerHTML = '关闭';
          elem.className += ' show';
        });
      }else {
        oRemoveCell.forEach((elem)=> {
          oEditBtn.innerHTML = '编辑';
          elem.className += 'cell remove-cell';
        });
      }
    }
  }
}

